package com.fujimana.rockincat.restree.log;

public class LogManager {
	
	public static final String LOGGER_BINDER_CLASS_NAME = "com.fujimana.rockincat.restree.log.LoggerBinder";
	
	private static final LoggerFactory FACTORY; 
	
	static {
		LoggerFactory factory = null;
		try {
			Class<?> clazz = Class.forName(LOGGER_BINDER_CLASS_NAME);
			
			factory = (LoggerFactory) clazz.getMethod("bind").invoke(null);
			
		} catch (Exception e) {
			// Nothing to do.
		}
		
		if(factory == null) {
			factory = new NullLogerFactory();
		}
		
		FACTORY = factory;
	}

	public static Logger getLogger(Class<?> clazz) {
		return getLogger(clazz.getName());
	}

	public static Logger getLogger(String category) {
		return FACTORY.getLogger(category);
	}
	
	static class NullLogerFactory implements LoggerFactory {
		
		private Logger logger;
		
		NullLogerFactory() {
			logger = new Logger() {

				@Override
				public void debug(String message) {
				}

				@Override
				public void debug(String message, Throwable t) {
				}

				@Override
				public void error(String message) {
				}

				@Override
				public void error(String message, Throwable t) {
				}

				@Override
				public void fatal(String message) {
				}

				@Override
				public void fatal(String message, Throwable t) {
				}

				@Override
				public void info(String message) {
				}

				@Override
				public void info(String message, Throwable t) {
				}

				@Override
				public boolean isDebugEnabled() {
					return false;
				}

				@Override
				public boolean isErrorEnabled() {
					return false;
				}

				@Override
				public boolean isFatalEnabled() {
					return false;
				}

				@Override
				public boolean isInfoEnabled() {
					return false;
				}

				@Override
				public boolean isTraceEnabled() {
					return false;
				}

				@Override
				public boolean isWarnEnabled() {
					return false;
				}

				@Override
				public void trace(String message) {
				}

				@Override
				public void trace(String message, Throwable t) {
				}

				@Override
				public void warn(String message) {
				}

				@Override
				public void warn(String message, Throwable t) {
				}
				
			};
		}

		@Override
		public Logger getLogger(String category) {
			return logger;
		}
		
	}
}
